package com.dtstack.hive.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dtstack.hive.mapper.UserMapper;
import com.dtstack.hive.utils.HiveUtil;
import com.dtstack.hive.vo.UserVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * UserService
 *
 * <p>
 * </p>
 *
 * @author chuanbai
 * @date 2024/8/3
 */
@Service
public class UserService extends ServiceImpl<UserMapper, UserVo> {

    @Resource
    private HiveUtil hiveUtil;

    public void queryDataFromHive() {
        Connection conn = hiveUtil.getConnection();
        Statement stmt = null;
        ResultSet rs = null;
        try {
            stmt = conn.createStatement();
            rs = stmt.executeQuery("SELECT * FROM psn5");
            while (rs.next()) {
                System.out.println(rs.getString(1));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
